//
//  EFMentionDetailViewController.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/16.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFMentionDetailViewController.h"
#import "EFMentionDetailViewItem.h"
#import "iToast.h"

@interface EFMentionDetailViewController ()<UITableViewDelegate, UITableViewDataSource>

@property(strong,nonatomic)NSMutableArray* dataArray;
@property(strong,nonatomic)UITableView* tableView;

@end

@implementation EFMentionDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [self initData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.title = @"提现明细";
        self.dataArray = [NSMutableArray array];
    }
    return self;
}

-(void)initView{
    [self.view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:self.tableView];
}

-(void)initData{
    NSString* page = @"1";
    NSString* size = @"10";
    
    __weak typeof(self) weakSelf = self;
    [APP_CONTEXT.net getDrawalListWithPage:page size:size OnComplete:^(NSInteger code, NSDictionary *info, NSString *message) {
        if(code == 0){
            if ([info objectForKey:@"list"]) {
                NSArray *array = [info objectForKey:@"list"];
                int i = 1 ;
                for (NSDictionary *dic in array) {
                    EFMentionDetailViewItem *item = [EFMentionDetailViewItem yy_modelWithDictionary:dic];
                    item.index = [NSString stringWithFormat:@"%d.",i++];
                    [weakSelf.dataArray addObject:item];
                }
                
                if (array.count == 0) {
                    [weakSelf showEmptyViewWithMessage:@"无更多内容"];
                }
            }
            [weakSelf.tableView reloadData];
        }else{
            [[iToast makeText:message]show];
        }
        
    }];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    ICTableViewItem *item = self.dataArray[indexPath.row];
    return item.viewHeight;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.dataArray count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ICTableViewItem* item = self.dataArray[indexPath.row];
    NSString *identifier = NSStringFromClass(item.viewClass);
    ICTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil){
        cell = [[item.viewClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if ([item isKindOfClass:[ICTableViewItem class]]) {
        [cell setObject:item];
    }
    
    return cell;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kStatusBarHeight )];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = [UIColor clearColor];
    }
    return _tableView;
}



@end
